/*
 * user_token.h
 *
 *  Created on: 2012-7-5
 *      Author: ThinkPad
 */

#ifndef USER_TOKEN_H_
#define USER_TOKEN_H_

#include "stdnet.h"

#define MAX_FILE_NUM 256

/*user self define token*/
struct user_token
{
        uint32_t id;/*token id*/
        uint16_t type;/*token type*/
        uint16_t fmt;/*token format*/
        char  key[GUID_LEN];/*token guid key or session key*/

        ulong    offset;/*data  offset*/
        ulong    length;/*data  len*/
        ulong    count; /*trans count*/
        uint64_t index;/*data or file packet index*/
        uint64_t trans_size;/*total trans byte size */
        uint64_t have_trans_size;/*have trans byte size*/
        uint64_t last_size; /*last trans size*/

        int      filefd; /*file fd*/
        uint64_t hFile_size;/*hFile size*/
        uint64_t hFile_offset;/*hFile offset*/

        sockaddr_in local_addr; /*local addr ,bind addr ,udp receive addr*/
        sockaddr_in remote_addr;/*remote addr ,,udp send addr*/
        socklen_t   addr_len;

        uint16_t send_timeout;/*send time out seconds*/
        uint16_t receive_timeout;/*recv time out seconds*/
        uint16_t trans_file_timeout;/*trans_file time out seconds*/
        time_t   tConnTime;         /*connect time*/
        time_t   timeConnBegin;   /*begin time*/
        uint16_t connectionFlag;/*keep connect flag*/
        u_long   conn_index;/*connect index*/
        int      recv_send_flag;/*flag*/

        void *   privt;/*user self data ptr*/

        user_token()
        {
                id = 0;
                type = 0;
                index = 0;
                fmt = 0;
                memset(key,'\0',128);

                offset = 0;
                length = 0;
                count = 0;
                trans_size = 0;
                have_trans_size = 0;
                last_size = 0;

                filefd = -1;
                hFile_size = 0;
                hFile_offset = 0;

                send_timeout = 0;
                receive_timeout = 0;
                trans_file_timeout = 0;
                tConnTime = time(NULL);
                timeConnBegin = time(NULL);
                connectionFlag = 0;
                recv_send_flag = 0;
                conn_index = 0;

                local_addr.sin_family = AF_INET;
                remote_addr.sin_family = AF_INET;
                addr_len = sizeof(remote_addr);

                privt = NULL;
        }
};

#endif /* USER_TOKEN_H_ */
